package server;

/**
 * Represents a Card Object. It has his own suit and number. It is going to be
 * serialized by this two inner values.
 */
public class Card {
	CardSuits suit;
	int number;
	
	
	public Card(CardSuits suit, int number) {
		super();
		this.suit = suit;
		this.number = number;
	}
	
	public CardSuits getSuit(){
		return this.suit;
	}
	
	public int getNumber(){
		return this.number;
	}

	@Override
	public String toString() {
		return "Card [suit=" + suit + ", number=" + number + "]";
	}

	/**
	 * Compares to cards for equality.
	 * 
	 * Two cards are equals, if both suit and number are equals.
	 */
	@Override
	public boolean equals(Object obj) {
	
		if (obj==null) return false;
		
		if (this.getClass()!=obj.getClass()) return false;
		
		return 
			(this.suit==null ? ((Card)obj).suit==null : this.suit.equals(((Card)obj).suit) )  &&  
			(this.number == ((Card)obj).number);
		
	}
	
	/**
	 * Compares two cards for equal Suit.
	 * 
	 * If the two cards has the same suit <code>true</code> is returned. <code>False</code> is returned else.
	 */
	public boolean sameSuit(Card otherCard) {
		return this.suit.equals(otherCard.suit);
	}

	/**
	 * Compares two cards values. Despite their suits.
	 * 
	 * If the first card is greater than the second <code>true</code> is returned. <code>False</code> is returned else.
	 */
	public boolean greaterValue(Card otherCard) {
		return this.number>otherCard.number;
	}

	/**
	 * Compares two cards value if they are of the same suit..
	 * 
	 * If the first card is greater than the second and both are of the same suit <code>true</code> is returned. <code>False</code> is returned else.
	 */
	public boolean greaterOfTheSameSuit(Card otherCard) {
		return this.greaterValue(otherCard) && this.sameSuit(otherCard);
	}
}
